﻿using System;
using System.Windows.Forms;

namespace TISS_Add_in
{
    public partial class uc_CodigoPrestador : UserControl
    {
        private string xPath;
        private string campoEscolhido = "cpf";
        private Microsoft.Office.Interop.Word.ContentControl cc = null;
        
        public delegate void identificacaoSelectedHandler(string identificacao, string xPath, Microsoft.Office.Interop.Word.ContentControl cc);
        public event identificacaoSelectedHandler identificacaoChanged;

        public uc_CodigoPrestador(string tipoIdentificacaoNaoChecado, string xPath, Microsoft.Office.Interop.Word.ContentControl contentControl)
        {
            InitializeComponent();

            this.xPath = xPath;
            this.cc = contentControl;

            rbCPF.CheckedChanged += new EventHandler(rbCPF_CheckedChanged);
            rbCNPJ.CheckedChanged += new EventHandler(rbCNPJ_CheckedChanged);
            rbCodOperadora.CheckedChanged += new EventHandler(rbCodOperadora_CheckedChanged);


            switch (tipoIdentificacaoNaoChecado)
            {
                case "CPF":
                    rbCPF.Enabled = false;
                    break;
                case "CNPJ":
                    rbCNPJ.Enabled = false;
                    break;
                case "CodigoOperadora":
                    rbCodOperadora.Enabled = false;
                    break;
                default:
                    break;
            }
        }

        void rbCodOperadora_CheckedChanged(object sender, EventArgs e)
        {
            if (rbCodOperadora.Checked)
                campoEscolhido = "codigoPrestadorNaOperadora";
        }

        void rbCPF_CheckedChanged(object sender, EventArgs e)
        {
            if (rbCPF.Checked)
                campoEscolhido = "cpf";
        }

        void rbCNPJ_CheckedChanged(object sender, EventArgs e)
        {
            if (rbCNPJ.Checked)
                campoEscolhido = "CNPJ";
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            identificacaoChanged(campoEscolhido, xPath, this.cc);
            Globals.ThisAddIn.CustomTaskPanes.Remove(Globals.ThisAddIn.CodigoPrestadorCTP);
        }
        
    }
}
